/*
 * The National Parks Database Project
 * Group: Tyler Simrell, Vladmir Dudnic, Michael Jagielo
 * LowerPanel.java
 */

package panels;

import gui.MainFrame;

import java.awt.CardLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

/**
 * This JPanel class holds a picture of the National Parks Logo along with the main menu
 * button (unless you are already on the main menu). Something to note is the fact that
 * this is attached to all cards, not simply attached to the cardPanel itself. The reason
 * is the GUI editor is rather temperamental, so it was decided to create a new panel at
 * the bottom of each card.
 * @author Tyler Simrell
 * @version 5/24/13
 *
 */
@SuppressWarnings("serial")
public class LowerPanel extends JPanel implements ActionListener
{
	CardLayout cards;
	JPanel cardPanel;
	boolean menuButton;
	
	/**
	 * This constructor takes in the CardLayout and JPanel that the cards sit on. Unlike
	 * the other card panels, this panel has a boolean determining whether a panel gets a 
	 * main menu button or not. 
	 *  
	 * @param passedInCards The passed in CardLayout
	 * @param passedInParentPanel The passed in JPanel where the cards sit.
	 * @param hasMenuButton A boolean determining whether a panel gets a main menu button.
	 */
	public LowerPanel(CardLayout passedInCards, JPanel passedInParentPanel, 
			boolean hasMenuButton)
	{
		super();
		cards = passedInCards;
		cardPanel = passedInParentPanel;
		menuButton = hasMenuButton;
		setUp();
	}
	
	/**
	 * This method does much of the heavy lifting in regards to setting up the GUI by setting up all
	 * of the components of the JPanel.
	 */
	private void setUp()
	{
		this.setBounds(0, 444, 844, 106);
		this.setLayout(null);
		
		JLabel nationalParksLogo = new JLabel();
		nationalParksLogo.setBounds(0, 0, 95, 106);
		this.add(nationalParksLogo);
		try
		{
			ImageIcon logo = new ImageIcon(getClass().getResource("/logo.png"));
			nationalParksLogo.setIcon(logo);
		}
		catch(NullPointerException exception)
		{
			//don't add the picture.
		}
		
		
		if(menuButton)
		{
			JButton mainMenuButton = new JButton("Main Menu");
			mainMenuButton.setLocation(737, 45);
			mainMenuButton.setSize(95, 26);
			mainMenuButton.setVerticalAlignment(SwingConstants.BOTTOM);
			mainMenuButton.addActionListener(this);
			this.add(mainMenuButton);
		}
	}
	
	/**
	 * This method services the main menu button. When pressed, the button brings up a dialog box
	 * asking if the user really wants to leave their current page.
	 */
	public void actionPerformed(ActionEvent e) 
	{
		int answer = JOptionPane.showConfirmDialog(null, "Are you sure you want to go to the main menu?",
				"Leave Current Page?", JOptionPane.YES_NO_OPTION);
		if(answer == JOptionPane.OK_OPTION)
		{
			cards.show(cardPanel, MainFrame.WELCOME_PANEL);
		}
	}
	
}
